fix: resolve panic when adding list entry before existing one#495
Open
ChristopherJHart wants to merge 1 commit intoCiscoDevNet:mainfrom
Open
fix: resolve panic when adding list entry before existing one#495ChristopherJHart wants to merge 1 commit intoCiscoDevNet:mainfrom
ChristopherJHart wants to merge 1 commit intoCiscoDevNet:mainfrom
Conversation
The getDeletedItems (RESTCONF) and addDeletedItemsXML (NETCONF) template functions had swapped loop indices when comparing list-type attributes within list entries. When i iterates state and j is the matched index in data, the code incorrectly read data[i] and state[j], causing an index-out-of-range panic whenever j > len(state)-1 (i.e., a new entry is inserted before an existing one). Fixed at both nesting levels in both functions (4 sites total in gen/templates/model.go). Affects iosxe_route_map, iosxe_crypto_pki, iosxe_radius_server, and iosxe_system generated models. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> AI-Generated: yes AI-Tool: claude-code AI-Model: opus-4.6 AI-Percent: 50 AI-Reason: fix swapped i/j indices in list-diff template
e02e374 to
7dda581
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
getDeletedItems(RESTCONF) andaddDeletedItemsXML(NETCONF) code generator template had swappedi/jloop indices in list-attribute diff branches, causing a panic when a new list entry is inserted before an existing onegen/templates/model.go(2 functions x 2 nesting levels), then regenerated all affected model files viamake geniosxe_route_map,iosxe_crypto_pki,iosxe_radius_server, andiosxe_systemRoot Cause
In
addDeletedItemsXMLandgetDeletedItems, the outer loop iteratesstate.Entrieswith indexi, and the inner loop searchesdata.Entriesfor a matching key, yielding indexj. Scalar attribute checks correctly usedstate[i]anddata[j], but list-type attribute diff branches had them swapped:When a new entry with a lower sequence number is added (e.g., seq 500 before existing seq 1000), the existing entry shifts to a higher index in
data.Entries, makingj > i. Sincestate.Entriesstill haslen = i + 1, accessingstate.Entries[j]panics withindex out of range.The bug was introduced in
getDeletedItemsby commit1ac6d2a3(2023-09-20) and copied intoaddDeletedItemsXMLby commit2b9d4955(2025-11-09).Reproduction
Verified on both protocol paths using C8000V devices running IOS-XE 17.15:
match_ip_address_prefix_listsgetDeletedItems:5392) and NETCONF (addDeletedItemsXML:6436)Test plan
getDeletedItems)addDeletedItemsXML)make test)🤖 AI Generation Metadata
🤖 Generated with Claude Code